<template>
  <div class="card-box">
    <van-loading :fix="true" v-if="loading"></van-loading>
    <van-row v-else class="card-list" :gutter="16">
      <van-col :span="24" v-for="item in list" :key="item.id">
        <div class="customer-card">
          <div class="card-header">
            {{ item.text }}
          </div>
          <div class="card-content">
            <span
              v-for="child in item.children"
              @click="emit('click', item, child)"
              :key="child.id"
            >
              {{ child.text }}
            </span>
          </div>
        </div>
      </van-col>
    </van-row>
  </div>
</template>

<script setup>
import { ref, watch } from 'vue'

const emit = defineEmits(['click'])
const props = defineProps({
  kbId: {
    type: String,
    default: '',
  },
  preQueData: {
    type: Array,
    default: () => [],
  },
})
const loading = ref(false)
const list = ref([])

watch(
  () => props.preQueData,
  val => {
    if (val) {
      list.value = val
    }
  },
  { immediate: true },
)
</script>

<style lang="stylus" scoped>
.card-box{
  position: relative;
  width 100%;
  height calc(100% - 42px);
}
.card-list {
  .van-col{
    margin-bottom 8px;
  }

  .customer-card {
    display flex;
    justify-content: space-between;
    border: 1px solid #e5e9ef;
    border-radius: 8px;

    .card-header {
      display: flex;
      align-items: center;

      border-radius: 8px 8px 0 0;
      background: #f4f9fd;
      color: #222;
      font-weight: 600;
      -webkit-font-smoothing: antialiased;
      font-size: 14px;
      padding: 0 10px;
      justify-content: center;
      width: 30%;
    }

    .card-content {
      display: flex;
      flex-wrap wrap;
      width: 70%;
      height: 100%;
      justify-content: flex-start;

      span {
        box-sizing border-box;
        padding: 10px;
        color: #222;
        font-size: 15px;
        transition: .3s;
        cursor pointer;
        width: 50%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        border-left: 1px solid #e8ebf0;
        border-bottom: 1px solid #e8ebf0;
        text-align: center;
        &:nth-last-child(-n+1){
          border-bottom: none;
        }
        &:hover{
          color: #1089ff;
        }
      }
    }
  }
}
</style>
